const errorTypes = require('../contants/error-types')

module.exports = async (error, ctx) => {
  let statusCode = 0  // HTTP状态码
  let returnCode = 0  // 业务状态码
  let message = ''  // 业务错误信息

  switch (error.message) {
    case errorTypes.BANNER_DOES_NOT_EXIST:
      statusCode = 400
      returnCode = 40000
      message = '请求的banner不存在'
      break;
    
    case errorTypes.THEME_DOES_NOT_EXIST:
      statusCode = 400
      returnCode = 30000
      message = '请求的主题不存在'
      break;
    
    case errorTypes.UNAUTHORIZATION:
      statusCode = 401
      returnCode = 10002
      message = '无效的token~'
      break;  
  
    default:
      break;
  }

  ctx.status = statusCode
  ctx.body = {
    returnCode,
    message
  }

} 












